//
//  ArrrayDataSource.m
//  UI27_block ArrayDataSource
//
//  Created by dllo on 16/8/19.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ArrrayDataSource.h"

@interface ArrrayDataSource ()
@property (nonatomic, copy) NSString *reuse;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, copy) configCell configCell;

@end


@implementation ArrrayDataSource

- (instancetype)initWithTableViewCellRuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)cell{
    self = [super init];
    if (self) {
        _reuse = reuse;
        _dataArray = array;
        _configCell = cell;
    }
    return self;
}

+ (ArrrayDataSource *)arrrayDataSourceWithTableViewCellRuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)cell {
    return [[self alloc] initWithTableViewCellRuse:reuse arrayDataSource:array configCell:cell];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuse];
    id model = _dataArray[indexPath.row];
    // 根据数据源和cell调用block
    self.configCell(cell, model);
    
    return cell;
}




@end
